<?php

/* 
  This file is responsible for the download of the files
*/

require_once('../../../wp-config.php');

global $user_ID, $wpdb, $table_prefix;
require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); 
include_once("uploader_functions.php");



  $id = (int) $_GET['file'];
  $result = $wpdb->get_row("SELECT fileName, type, title, downloads
                            FROM ".$table_prefix."document
                            WHERE id = ".$id."
                           ;");
  
  $downloads = $result->downloads + 1;
  $wpdb->query("UPDATE ".$table_prefix."document 
                      SET downloads = ".$downloads."
                      WHERE id = ".$id.";");
  $fTitle = $result->title;                         
  $fPath = $result->fileName;
  //echo $fPath; 
  $fType = wpup_upGetType($result->type)->extName;
  $string = explode('/', $fPath);
  $size = count($string);
 //print_r($string);
  header('Content-type: ".$fType."');
  
  //echo $string[$size-1];
  
  header('Content-Disposition: attachment; filename="'.$string[$size-1].'"');


  $permission = "all";
  $plugin_name = "wp_uploader";
  if (class_exists("userGroups"))
    $user = new userGroups;
    
  if (class_exists("userGroups") && $user->ugHasAccess($user_ID, $id, $permission, $plugin_name))
    readfile($fPath);
    
  if (!class_exists("userGroups"))
    readfile($fPath);

?> 
